Imports CapaDeNegocios
Partial Public Class ABMTipoTalonario
    Inherits System.Web.UI.Page
    Private TblTipoTalonario As nTipoTalonario = New CapaDeNegocios.nTipoTalonario()
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            LLenar_Grid()
        End If
    End Sub
    Sub LLenar_Grid()
        GVTipoTalonario.DataSource = TblTipoTalonario.Listar()
        GVTipoTalonario.DataBind()
        LimpiarCampos()
        GVTipoTalonario.SelectedIndex = -1
    End Sub
    Sub LimpiarCampos()
        TxtId.Value = ""
        TxtDescripcion.Text = ""
        LblError.Text = ""
    End Sub

    Protected Sub LnkGuardar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LnkGuardar.Click
        If DDLLetra.SelectedValue <> "Ninguno" Then
            If TxtId.Value = "" Then
                If TxtDescripcion.Text <> "" Then
                    If Not TblTipoTalonario.Insertar(DDLLetra.Text, TxtDescripcion.Text) Then
                        LblError.Text = "Error de Insercion"
                    Else
                        LLenar_Grid()
                    End If

                End If
            Else
                If Not TblTipoTalonario.Modificar(TxtId.Value, DDLLetra.Text, TxtDescripcion.Text) Then
                    LblError.Text = "Error de Actualizacion"
                Else
                    LLenar_Grid()
                End If
            End If
        Else
            LblError.Text = "Error, Elija un tipo de talonario..."
        End If

    End Sub

    
    Protected Sub LnkEliminar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LnkEliminar.Click

        If TxtId.Value <> "" Then
            If Not TblTipoTalonario.Eliminar(TxtId.Value) Then
                LblError.Text = "Error de Eliminacion. verifique que no se este usando este Tipo de Talonario."
            Else
                LLenar_Grid()
            End If

        End If
    End Sub


    Protected Sub LnkBuscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LnkBuscar.Click
        GVTipoTalonario.DataSource = TblTipoTalonario.Buscar(TxtId.Value, DDLLetra.SelectedValue, TxtDescripcion.Text)
        GVTipoTalonario.DataBind()

    End Sub

    Protected Sub GVTipoTalonario_RowCommand(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GVTipoTalonario.RowCommand
        If e.CommandName = "Select" Then
            TxtId.Value = e.CommandSource.Parent.FindControl("HFIdTipoTalonario").value
            TxtDescripcion.Text = e.CommandSource.Parent.Parent.FindControl("lblDescripcion").text
            DDLLetra.Text = DDLLetra.Items.FindByText(e.CommandSource.Parent.Parent.FindControl("lblLetra").text).Text
        End If
    End Sub

    Protected Sub LnkCancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LnkCancelar.Click
        LLenar_Grid()
    End Sub


End Class